package com.pucong.gitee.database.backup.business.unRelational.redis.controller;

import com.pucong.gitee.database.backup.business.unRelational.redis.service.InfoClusterService;
import com.pucong.gitee.database.backup.business.unRelational.redis.util.ClusterRelation;
import com.pucong.gitee.database.backup.common.entity.redis.RedisInfo;
import com.pucong.gitee.database.backup.common.entity.redis.vo.RedisGetKeyInfo;
import com.pucong.gitee.database.backup.common.entity.redis.vo.RedisNetInfo;
import com.pucong.gitee.database.backup.utils.Res;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/auto/redis/infoCluster")
public class InfoClusterController {

    @Autowired
    private InfoClusterService infoClusterService;

    /**
     * 获取基础服务信息
     */
    @GetMapping("/getBaseInfo/{id}")
    public Res<RedisInfo> getBaseInfo(@ApiParam("主键") @PathVariable("id") String id) {
        RedisInfo redisInfo = infoClusterService.getBaseInfo(id);
        return Res.ok(redisInfo);
    }


    /**
     * 获取服务日志信息
     */
    @GetMapping("/getNodeInfo/{id}")
    public Res<List<ClusterRelation>> getNodeInfo(@ApiParam("主键") @PathVariable("id") String id) {
        List<ClusterRelation> clusterRelationList = infoClusterService.getNodeInfo(id);
        return Res.ok(clusterRelationList);
    }


    /**
     * 监控服务内存信息
     */
    @GetMapping("/getMemInfo/{id}")
    public Res<RedisNetInfo> getMemInfo(@ApiParam("主键") @PathVariable("id") String id) {
        RedisNetInfo redisNetInfo = infoClusterService.getMemInfo(id);
        return Res.ok(redisNetInfo);
    }


    /**
     * 监控服务处理器信息
     */
    @GetMapping("/getCpuInfo/{id}")
    public Res<RedisInfo> getCpuInfo(@ApiParam("主键") @PathVariable("id") String id) {
        RedisNetInfo redisNetInfo = infoClusterService.getCpuInfo(id);
        return Res.ok(redisNetInfo);
    }

    /**
     * 监控服务数据库信息
     */
    @GetMapping("/getKeyInfo/{id}")
    public Res<RedisGetKeyInfo> getKeyInfo(@ApiParam("主键") @PathVariable("id") String id) {
        RedisGetKeyInfo redisGetKeyInfo = infoClusterService.getKeyInfo(id);
        return Res.ok(redisGetKeyInfo);
    }

    /**
     * 监控服务网络信息
     */
    @GetMapping("/getNetInfo/{id}")
    public Res<RedisNetInfo> getNetInfo(@ApiParam("主键") @PathVariable("id") String id) {
        RedisNetInfo redisNetInfo = infoClusterService.getNetInfo(id);
        return Res.ok(redisNetInfo);
    }
}

